/**
 * Courtesy of http://stackoverflow.com/questions/3914852/problem-getting-same-class-instance-passed-from-one-activity-to-another
 * Parcelable creates a serializable object that can be passed through intent to different activities.
 * But this class failed miserably...so switched to ApplicationCode
 */


package com.cps116.resource;


import com.easy.facebook.android.facebook.Facebook;
import android.os.Parcel;
import android.os.Parcelable;

public class FacebookParcelable implements Parcelable
{

	private Facebook facebook;
	
	public FacebookParcelable() { ; }

	/**
	 *
	 * Constructor to use when re-constructing object
	 * from a parcel
	 *
	 * @param in a parcel from which to read this object
	 */
	public FacebookParcelable(Parcel in) {
		readFromParcel(in);
	}

	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void writeToParcel(Parcel dest, int flags) 
	{
		// TODO Auto-generated method stub
		dest.writeValue(getFacebook());
	}

	private void readFromParcel(Parcel in) {

		// readParcelable needs the ClassLoader
		// but that can be picked up from the class
		// This will solve the BadParcelableException
		// because of ClassNotFoundException
		facebook = (Facebook) in.readValue(Facebook.class.getClassLoader());

	}

	public void setFacebook(Facebook facebook) {
		this.facebook = facebook;
	}

	public Facebook getFacebook() {
		return facebook;
	}

	
	public static final Parcelable.Creator<FacebookParcelable> CREATOR =
			new Parcelable.Creator<FacebookParcelable>()
			{
		public FacebookParcelable createFromParcel(Parcel in)
		{
			return new FacebookParcelable(in);
		}

		public FacebookParcelable[] newArray(int size) {
			return new FacebookParcelable[size];
		}
			};

}